layui.define(['layer', 'conf', 'jquery'], function(exports){
	var $ = layui.jquery;
	var conf = layui.conf;
	var Msg = function(){}
	var msgShowTime = conf.msgShowTime || 2000;
	
	var getLoadHtml = function(msg){
		var loadHtml = '<div class="layui-loading-custom" style="position:absolute;left:0;right:0;top:0;bottom:0;text-align:center;font-size:80px !important;display:flex;flex-direction:row;justify-content:center;align-items:center;">' +
		'<div style="font-size:16px !important;margin: 0 auto;color:#666">' + 
		'<i class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop" style="font-size:16px"></i>';
		if(msg){
			loadHtml += ' <span>' + msg +'</span>';
		}		 
		loadHtml += '</div>' + 
		'<div style="position:absolute;left:0;right:0;top:0;bottom:0;background;background-color: rgb(0, 0, 0);opacity: 0.09;" class=""></div>' +
		'</div>';
		return loadHtml;
	}
	
	Msg.prototype.load = function(msg, o){		
		if(typeof msg == 'object' && msg){			
			o = msg;
			msg =  conf.loading;
		}else{
			msg = msg ? msg : conf.loading; 
		}
				
		//指定dom元素内显示loading
		if(o && o.dom){			
			var $dom = $(o.dom);			
			if($dom.length <= 0 || $dom.children(".layui-loading-custom").length > 0){
				return;
			}					 
			$dom.append(getLoadHtml(msg));			
			return;
		}
		
		
		var loadingIndex = layer.msg(msg, {
		  icon: 16
		  ,shade: 0.01,
		  time:0
		})
		if(Msg.loadingIndex){
			layer.close(Msg.loadingIndex);
			delete Msg.loadingIndex;
		}
		Msg.loadingIndex = loadingIndex;
		return loadingIndex
	}
	
	Msg.prototype.removeLoad = function(o){
		o = o || {};
		if(o.dom){
			var $dom = $(o.dom);
			if($dom.length <= 0){
				return;
			}
			$dom.children(".layui-loading-custom").remove();
			return;
		}
		layer.close(Msg.loadingIndex);
		delete Msg.loadingIndex
	}
	
	Msg.prototype.success =function(msg, fun){
		layer.msg(msg, {
				icon : 1,
				time : msgShowTime
		}, fun)
	}
	
	Msg.prototype.error = function(msg, fun){
		layer.msg(msg, {
			icon : 2,
			time : msgShowTime
		}, fun)
	}
	
	Msg.prototype.warn = function(msg){
		layer.msg(msg, {
			icon : 7,
			time : msgShowTime
		})
	}
	
	Msg.prototype.confirm = function(msg, yes, cancel){
		layer.confirm(msg, {icon: 3, title:'提示'}, yes, cancel)
	}
	
	msg = new Msg();
	exports("msg", msg)
})